package com.lvy.hczn.front.business.controller;

import java.util.List;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lvy.hczn.front.business.service.WarehouseBoxOutboundService;
import com.lvy.hczn.front.common.constant.Constants;
import com.lvy.hczn.front.system.domain.business.GoodsBoxSpec;
import com.lvy.hczn.front.system.domain.business.Warehouse;
import com.lvy.hczn.front.system.domain.business.WarehouseBoxOutbound;
import com.lvy.hczn.front.system.service.GoodsBoxSpecService;
import com.lvy.hczn.front.system.service.WarehouseService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.lvy.hczn.front.common.annotation.Log;
import com.lvy.hczn.front.common.enums.BusinessType;
import com.lvy.hczn.front.common.core.controller.BaseController;
import com.lvy.hczn.front.common.core.domain.AjaxResult;
import com.lvy.hczn.front.common.utils.poi.ExcelUtil;
import com.lvy.hczn.front.common.core.page.TableDataInfo;

/**
 * 货箱出库单Controller
 *
 * @author ruoyi
 * @date 2023-05-23
 */
@Controller
@RequestMapping("/system/box/outbound")
public class WarehouseBoxOutboundController extends BaseController {
    private String prefix = "system/boxoutbound";

    @Autowired
    private WarehouseBoxOutboundService warehouseBoxOutboundService;

    @Autowired
    private GoodsBoxSpecService goodsBoxSpecService;

    @Autowired
    private WarehouseService warehouseService;

    @RequiresPermissions("system:box:outbound:view")
    @GetMapping()
    public String outbound() {
        return prefix + "/outbound";
    }

    /**
     * 查询货箱出库单列表
     */
    @RequiresPermissions("system:box:outbound:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WarehouseBoxOutbound warehouseBoxOutbound) {
        startPage();
        List<WarehouseBoxOutbound> list = warehouseBoxOutboundService.selectWarehouseBoxOutboundList(warehouseBoxOutbound);
        return getDataTable(list);
    }

    /**
     * 导出货箱出库单列表
     */
    @RequiresPermissions("system:box:outbound:export")
    @Log(title = "货箱出库单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WarehouseBoxOutbound warehouseBoxOutbound) {
        List<WarehouseBoxOutbound> list = warehouseBoxOutboundService.selectWarehouseBoxOutboundList(warehouseBoxOutbound);
        ExcelUtil<WarehouseBoxOutbound> util = new ExcelUtil<WarehouseBoxOutbound>(WarehouseBoxOutbound.class);
        return util.exportExcel(list, "货箱出库单数据");
    }

    /**
     * 新增货箱出库单
     */
    @GetMapping("/add")
    public String add(ModelMap mmap) {
        Warehouse warehouse = warehouseService.selectLocalWarehouseFront();
        List<GoodsBoxSpec> list = goodsBoxSpecService.list(Wrappers.<GoodsBoxSpec>lambdaQuery().eq(GoodsBoxSpec::getIsDelete, Constants.IS_DELETE_FALSE));
        mmap.put("warehouse", warehouse);
        mmap.put("list", list);
        return prefix + "/add";
    }

    /**
     * 新增保存货箱出库单
     */
    @RequiresPermissions("system:box:outbound:add")
    @Log(title = "货箱出库单", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WarehouseBoxOutbound warehouseBoxOutbound) {
        return toAjax(warehouseBoxOutboundService.insertWarehouseBoxOutbound(warehouseBoxOutbound));
    }

    /**
     * 修改货箱出库单
     */
    @RequiresPermissions("system:box:outbound:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        WarehouseBoxOutbound warehouseBoxOutbound = warehouseBoxOutboundService.selectWarehouseBoxOutboundById(id);
        mmap.put("warehouseBoxOutbound", warehouseBoxOutbound);
        return prefix + "/edit";
    }

    /**
     * 修改保存货箱出库单
     */
    @RequiresPermissions("system:box:outbound:edit")
    @Log(title = "货箱出库单", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WarehouseBoxOutbound warehouseBoxOutbound) {
        return toAjax(warehouseBoxOutboundService.updateWarehouseBoxOutbound(warehouseBoxOutbound));
    }

    /**
     * 删除货箱出库单
     */
    @RequiresPermissions("system:box:outbound:remove")
    @Log(title = "货箱出库单", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(warehouseBoxOutboundService.deleteWarehouseBoxOutboundByIds(ids));
    }
}
